package com.ppch.zerocodegenerator.service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.service.IService;
import com.ppch.zerocodegenerator.exception.ErrorCode;
import com.ppch.zerocodegenerator.exception.ThrowUtils;
import com.ppch.zerocodegenerator.model.constant.UserConstant;
import com.ppch.zerocodegenerator.model.dto.chathistory.ChatHistoryQueryRequest;
import com.ppch.zerocodegenerator.model.entity.App;
import com.ppch.zerocodegenerator.model.entity.ChatHistory;
import com.ppch.zerocodegenerator.model.entity.User;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;

import java.time.LocalDateTime;

/**
 * 对话历史 服务层。
 *
 * @author 泡泡茶壶
 * @since 2025-10-5
 */
public interface ChatHistoryService extends IService<ChatHistory> {

    boolean addChatMessage(Long appId, String message, String messageType, Long userId);

    int loadChatHistoryToMemory(Long appId, MessageWindowChatMemory chatMemory, int maxCount);

    /**
     * 根据应用ID删除该应用下的所有对话历史
     * @param appId 应用ID
     * @return 是否成功
     */
    boolean deleteAllChatHistoryByAppId(Long appId);

    /**
     * 根据对话记录ID删除对应的一条对话历史
     * @param id 对话记录ID
     * @return 是否成功
     */
    boolean deleteOneChatHistoryById(Long id);

    QueryWrapper getQueryWrapper(ChatHistoryQueryRequest chatHistoryQueryRequest);

    Page<ChatHistory> listAppChatHistoryByPage(Long appId, int pageSize, LocalDateTime lastCreateTime, User loginUser);

}
